<!--
 * @Descripttion: HN-SaaS管理系统
 * @version: 1.0.0
 * @Author: 侯建军
 * @Date: 2020-09-11 13:15:40
 * @LastEditors: 侯建军
 * @LastEditTime: 2020-09-12 11:22:14
-->
<template>
  <div>
    <el-container>
      <el-aside width="300px">
        <el-form :model="inspectItem" class="inspectItem">
          <el-form-item label="项目名称">
            <el-input v-model="inspectItem.name" placeholder="项目名称(必填)"></el-input>
          </el-form-item>
          <el-form-item label="项目类型">
            <el-radio-group v-model="inspectItem.itemType">
              <el-radio :label="0">检查</el-radio>
              <el-radio :label="1">检验</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="价格">
            <el-input v-model="inspectItem.price"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">添加</el-button>
          </el-form-item>
        </el-form>
      </el-aside>
      <el-main>
        <!-- 表格  -->
        <el-table :data="itemData" style="width: 100%" class="itemData">
          <el-table-column prop="name" label="名称" width="180"></el-table-column>
          <el-table-column prop="itemType" label="类型" width="180">
            <template slot-scope="scope">
              <el-tag
                :type="scope.row.itemType == '0' ? 'warning' : 'success'"
                close-transition
              >{{scope.row.itemType=='0'?'检查':'检验'}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="price" label="价格(元)" width="180"></el-table-column>
        </el-table>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import { insert, getInspectItems } from "@/api/inspectItem.js";

export default {
  name: "",
  data() {
    return {
      inspectItem: { itemType: 0 },
      itemData: [],
    };
  },
  created() {
    this.loadData();
  },
  methods: {
    loadData() {
      getInspectItems().then((res) => {
        this.itemData = res.data.data;
      });
    },
    onSubmit() {
      insert(this.inspectItem).then((res) => {
        this.$message({
          message: res.data.msg,
          type: "success",
        });
        this.loadData();
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.inspectItem {
  width: 100%;
}
.itemData{
    margin-left: 20px;
}
</style>